﻿''' <summary>
''' Diese Klasse ist die Basisklasse für Hauptmenü usw..
''' </summary>
''' <remarks></remarks>
Public MustInherit Class ObjektFormMenü
    Public Knöpfe() As ObjektButton = {}
    Public Taskleiste As ObjektTaskleiste
    Public NUDS() As ObjektNumericUpDown = {}
    Public SUDS() As ObjektStringUpDown = {}
    Public Box As ObjektBox
    Public Values As ObjektValueSchieber() = {}
    Public MultiValues As ObjektMultiValue() = {}
    Public CheckBoxen As ObjektCheckBox() = {}
    Public Labels() As ObjektLabel = {}
    Public DropDownMenüs As ObjektDropDownMenü() = {}
    Public Textboxen As ObjektTextbox() = {}
    Public Panels() As ObjektPanel = {}
    Public Sub New(ByVal Knöpfe() As ObjektButton, ByVal Taskleiste As ObjektTaskleiste, ByVal NUDS() As ObjektNumericUpDown, ByVal Box As ObjektBox, ByVal Values() As ObjektValueSchieber, ByVal MultiValues() As ObjektMultiValue, ByVal Checkboxen As ObjektCheckBox())
        Me.Knöpfe = Knöpfe
        Me.Taskleiste = Taskleiste
        Me.NUDS = NUDS
        Me.Box = Box
        Me.CheckBoxen = Checkboxen
        Me.Values = Values
        Me.MultiValues = MultiValues
    End Sub
    Public Sub New()
        Me.Knöpfe = New ObjektButton() {}
        Taskleiste = Nothing
        Me.NUDS = New ObjektNumericUpDown() {}
        Box = Nothing
        Me.Values = New ObjektValueSchieber() {}
        Me.MultiValues = New ObjektMultiValue() {}
        Me.CheckBoxen = New ObjektCheckBox() {}
    End Sub
    Public MustOverride Sub IniMenü()
#Region "Events"
    Public MustOverride Sub KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
    Public MustOverride Sub MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    Public MustOverride Sub MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    Public MustOverride Sub MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    Public MustOverride Sub MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
#End Region
#Region "Objekte überprüfen"
#Region "Mouse Up"
    Public Function checkMouseUPObjekte(ByVal X As Integer, ByVal Y As Integer) As String
        'Zuerst mal nachschauen ob wir nicht einen Focus haben.
        For I = 0 To Objekt2D.Objekte.Length - 1
            If Objekt2D.Objekte(I).Focused Then
                Return "ObjekthatFocus"
            End If
        Next
        For I = 0 To Panels.Length - 1
            Panels(I).MouseUp(X, Y)
        Next
        For I = 0 To Values.Length - 1
            Values(I).MouseUp(X, Y)
        Next
        For I = 0 To MultiValues.Length - 1
            MultiValues(I).MouseUp(X, Y)
        Next
        For I = 0 To NUDS.Length - 1
            NUDS(I).MouseUp(X, Y)
        Next
        For I = 0 To SUDS.Length - 1
            SUDS(I).MouseUp(X, Y)
        Next
        For I = 0 To CheckBoxen.Length - 1
            CheckBoxen(I).MouseUp(X, Y)
        Next
        Dim Funktion As String = ""
        'Wenn wir ein Einheitenmenü haben klicken wir drauf
        If Not Objektverwalter.EinheitenMenü Is Nothing Then Funktion = Objektverwalter.EinheitenMenü.CheckMouseDown
        'Falls wir einen Befehl haben können wir ihn ausführen
        If Not Funktion = "" Then
            Return Funktion
        End If

        If IsNothing(Box) = False Then
            Select Case Box.Zustand
                Case ObjektBox.Zustände.Keiner
                Case ObjektBox.Zustände.Abrechen
                    Funktion = Box.MouseUp(X, Y)
                Case ObjektBox.Zustände.NurBefehle
                    Funktion = Box.MouseUp(X, Y)
            End Select
        End If
        If Funktion = "" Then
            Funktion = checkMouseUPKnöpfe(X, Y)
            If Not Funktion = "" Then
                Return Funktion
            Else
                If IsNothing(Taskleiste) = False Then
                    Funktion = Taskleiste.MouseUP(X, Y)
                End If
                If Funktion = "" Then
                    Funktion = CheckUPNuds(X, Y)
                End If
                If Funktion = "" Then
                    Funktion = CheckMouseUpCheckBox(X, Y)
                End If
            End If
        End If
        Return Funktion
    End Function
    Private Function checkMouseUPKnöpfe(ByVal XKoo As Integer, ByVal YKoo As Integer) As String
        For I = 0 To Knöpfe.Length - 1
            Dim Funktion As String = Knöpfe(I).MouseUp(XKoo, YKoo)
            If Not Funktion = "" Then
                Return Funktion
            End If
        Next
        Return ""
    End Function
    Private Function CheckUPNuds(ByVal X As Integer, ByVal Y As Integer) As String
        For I = 0 To NUDS.Length - 1
            NUDS(I).MouseUp(X, Y)
        Next
        Return ""
    End Function
    Private Function CheckMouseUpCheckBox(ByVal X, ByVal Y) As String
        Dim Funktion As String
        For I = 0 To CheckBoxen.Length - 1
            Funktion = CheckBoxen(I).MouseUp(X, Y)
            If Funktion <> "" Then
                Return Funktion
            End If
        Next
        Return ""
    End Function
#End Region
#Region "Mouse Down"
    Public Sub checkMouseDownObjekte(ByVal X As Integer, ByVal Y As Integer)
        If IsNothing(Box) = False Then
            Select Case Box.Zustand
                Case ObjektBox.Zustände.Keiner
                    MouseDownOhneBox(X, Y)
                Case ObjektBox.Zustände.Abrechen
                    Box.MouseDown(X, Y)
                    Exit Sub
                Case ObjektBox.Zustände.NurBefehle
                    Box.MouseDown(X, Y)
                    Exit Sub
            End Select
        Else
            MouseDownOhneBox(X, Y)
        End If
       
    End Sub
    ''' <summary>
    ''' Überprüft ob auf einen Button geklickt wurde
    ''' </summary>
    ''' <param name="XKoo"></param>
    ''' <param name="YKoo"></param>
    ''' <remarks></remarks>
    Private Sub checkMousedownKnöpfe(ByVal XKoo As Integer, ByVal YKoo As Integer)
        For I = 0 To Knöpfe.Length - 1
            Knöpfe(I).MouseDown(XKoo, YKoo)
        Next
    End Sub
    Private Sub MouseDownOhneBox(ByVal X As Integer, ByVal Y As Integer)
        
        For I = 0 To Panels.Length - 1
            Panels(I).MouseDown(X, Y)
        Next
        checkMousedownKnöpfe(X, Y)
        If IsNothing(Taskleiste) = False Then
            Taskleiste.MouseDown(X, Y)
        End If
        For I = 0 To Values.Length - 1
            Values(I).MouseDown(X, Y)
        Next
        For I = 0 To NUDS.Length - 1
            NUDS(I).MouseDown(X, Y)
        Next
        For I = 0 To SUDS.Length - 1
            SUDS(I).MouseDown(X, Y)
        Next
        For I = 0 To MultiValues.Length - 1
            MultiValues(I).MouseDown(X, Y)
        Next
        For I = 0 To CheckBoxen.Length - 1
            CheckBoxen(I).MouseDown(X, Y)
        Next
    End Sub
#End Region
#Region "Mouse Move"
    Public Sub MouseMoveObjekte(ByVal X As Integer, ByVal Y As Integer)
        If Not Objektverwalter.EinheitenMenü Is Nothing Then
            Objektverwalter.EinheitenMenü.MouseMove(X, Y)
            Exit Sub
        End If
        If IsNothing(Box) = False Then
            Select Case Box.Zustand
                Case ObjektBox.Zustände.Keiner
                Case ObjektBox.Zustände.Abrechen
                    Box.MouseMove(X, Y)
                    Exit Sub
                Case ObjektBox.Zustände.NurBefehle
                    Box.MouseMove(X, Y)
                    Exit Sub
            End Select
        End If
        For I = 0 To Panels.Length - 1
            Panels(I).MouseMove(X, Y)
        Next
        MouseMoveButtons(X, Y)
        If IsNothing(Taskleiste) = False Then
            Taskleiste.MouseMove(X, Y)
        End If
        For I = 0 To Values.Length - 1
            Values(I).MouseMove(X, Y)
        Next
        For I = 0 To MultiValues.Length - 1
            MultiValues(I).MouseMove(X, Y)
        Next
    End Sub
    Private Sub MouseMoveButtons(ByVal XKoo As Integer, ByVal YKoo As Integer)
        For I = 0 To Knöpfe.Length - 1
            If Not Knöpfe(I) Is Nothing Then
                Knöpfe(I).MouseEnter(XKoo, YKoo)
            End If
        Next
    End Sub
#End Region
    Public MustOverride Sub SprachEingabe(ByVal Eingabe As String)
#End Region
#Region "Objekte erschaffen"
    Public Sub NeuButton(ByVal XKoomin As Integer, ByVal YKoomin As Integer, ByVal Bildpfad As String, ByVal Funktion As String, ByVal Fixed As PointF, Optional ByVal XBreite As Integer = Nothing, Optional ByVal YBreite As Integer = Nothing, Optional ByVal Zoom As Boolean = False, Optional ByVal Handler As ObjektPanel = Nothing)
        Dim Bild As Bitmap = Image.FromFile(Bildpfad)
        If XBreite = Nothing Then
            XBreite = Bild.Width / 2
        End If
        If YBreite = Nothing Then
            YBreite = Bild.Height
        End If
        SyncLock Knöpfe
            Array.Resize(Knöpfe, Knöpfe.Length + 1)
            Knöpfe(Knöpfe.Length - 1) = New ObjektButton(XKoomin, YKoomin, Bildpfad, Funktion, Fixed, Handler)
        End SyncLock
    End Sub
    ''' <summary>
    ''' Löscht ALLE Buttons die als Text, die angezeigte Funktion zeigen (Groß-/Kleinschreibung wird nicht berücksichtigt)
    ''' </summary>
    ''' <param name="Funktion"></param>
    ''' <remarks></remarks>
    Public Sub LöschenButton(ByVal Funktion As String)
        SyncLock Knöpfe
            Dim i As Integer = 0
            While i < Knöpfe.Length
                If Knöpfe(i).Tag.ToLower = Funktion.ToLower Then
                    Knöpfe(i) = Knöpfe(Knöpfe.Length - 1)
                    Array.Resize(Knöpfe, Knöpfe.Length - 1)
                Else
                    i += 1
                End If
            End While
        End SyncLock
    End Sub
    Public Sub LöschenPanel(ByVal I As Integer)
        Panels(I).RemoveHandles()
        Panels(I) = Panels(Panels.Length - 1)
        Array.Resize(Panels, Panels.Length - 1)
    End Sub
    ''' <summary>
    ''' Alle Knöpfe werden ohne ausnahme gelöscht.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub ResetButton()
        Array.Resize(Knöpfe, 0)
    End Sub
    Public Sub neuNUD(ByVal Startvalue As Integer, ByVal Min As Integer, ByVal Max As Integer, ByVal P As Point, ByVal Bild As String, ByVal Änderung As Integer, ByVal Fixed As PointF, Optional ByVal Handler As ObjektPanel = Nothing, Optional ByVal Infinite As Integer = -1)
        Array.Resize(NUDS, NUDS.Length + 1)
        NUDS(NUDS.Length - 1) = New ObjektNumericUpDown(Startvalue, Min, Max, Bild, P, Änderung, Fixed, Infinite, Handler)
    End Sub
    Public Sub NeuCheckBoxen(ByVal XKoomin As Integer, ByVal YKoomin As Integer, ByVal Bildpfad As String, ByVal Fixed As PointF, Optional ByVal Checked As Boolean = True, Optional ByVal Handler As ObjektPanel = Nothing)
        SyncLock CheckBoxen
            Array.Resize(CheckBoxen, CheckBoxen.Length + 1)
            CheckBoxen(CheckBoxen.Length - 1) = New ObjektCheckBox(New Point(XKoomin, YKoomin), Bildpfad, Fixed, Checked, Handler)
        End SyncLock
    End Sub
    Public Function ExistiertButton(ByVal Funktion As String) As Boolean
        For I = 0 To Knöpfe.Length - 1
            If Knöpfe(I).Tag.ToLower = Funktion.ToLower Then Return True
        Next
        Return False
    End Function
    Public Sub NeuStringUpDown(ByVal XKoomin As Integer, ByVal YKoomin As Integer, ByVal Bildpfad As String, ByVal Funktion As String(), ByVal Startvalue As Integer, ByVal Fixed As PointF, Optional ByVal Handler As ObjektPanel = Nothing)
        SyncLock SUDS
            Array.Resize(SUDS, SUDS.Length + 1)
            SUDS(SUDS.Length - 1) = New ObjektStringUpDown(Startvalue, Funktion, Bildpfad, New Point(XKoomin, YKoomin), Fixed, Handler)
        End SyncLock
    End Sub
    Public Sub NeuLabel(ByVal XKoomin As Integer, ByVal YKoomin As Integer, ByVal Text As String(), ByVal Fixed As PointF, Optional ByVal Handler As ObjektPanel = Nothing)
        SyncLock Labels
            Array.Resize(Labels, Labels.Length + 1)
            Labels(Labels.Length - 1) = New ObjektLabel(XKoomin, YKoomin, My.Settings.Resourcenpfad + "Objekte\Transparent.png", Text, New Point(0, 0), 10, 0, Fixed, Handler)
        End SyncLock
    End Sub
    Public Sub NeuTextFeld(ByVal X As Integer, ByVal Y As Integer, ByVal Breite As Integer, ByVal Fixed As PointF, Optional ByVal Handler As ObjektPanel = Nothing)
        Array.Resize(Textboxen, Textboxen.Length + 1)
        Textboxen(Textboxen.Length - 1) = New ObjektTextbox(X, Y, Breite, Fixed, Handler)
    End Sub
    Public Sub NeuDropDownMenü(ByVal X As Integer, ByVal Y As Integer, ByVal Items() As String, ByVal Fixed As PointF, Optional ByVal Handler As ObjektPanel = Nothing)
        Array.Resize(DropDownMenüs, DropDownMenüs.Length + 1)
        DropDownMenüs(DropDownMenüs.Length - 1) = New ObjektDropDownMenü(X, Y, Items, Fixed, , Handler)
    End Sub
    Public Sub NeuDropDownMenü(ByVal X As Integer, ByVal Y As Integer, ByVal Items() As Color, ByVal Fixed As PointF)
        Array.Resize(DropDownMenüs, DropDownMenüs.Length + 1)
        DropDownMenüs(DropDownMenüs.Length - 1) = New ObjektDropDownMenü(X, Y, Items, Fixed)
    End Sub
    Public Sub NeuPanel(ByVal Panel As ObjektPanel)
        Array.Resize(Panels, Panels.Length + 1)
        Panels(Panels.Length - 1) = Panel
    End Sub
#End Region
    Public MustOverride Sub Malen()
    Public MustOverride Sub SetMausBild()
    Public MustOverride Sub Frame()
    Public Overridable Sub Reset()

    End Sub
    Protected Sub ObjekteMalen()
        For I = 0 To Panels.Length - 1
            Panels(I).Malen()
        Next
        SyncLock Knöpfe
            For I As Integer = 0 To Knöpfe.Length - 1
                If Not Knöpfe(I) Is Nothing Then
                    Knöpfe(I).Malen()
                End If
            Next
        End SyncLock
        If IsNothing(Taskleiste) = False Then
            Taskleiste.Malen()
        End If
        For I = 0 To NUDS.Length - 1
            If Not NUDS(I) Is Nothing Then
                NUDS(I).Malen()
            End If
        Next
        For I = 0 To SUDS.Length - 1
            If Not SUDS(I) Is Nothing Then
                SUDS(I).Malen()
            End If
        Next
        For I = 0 To Values.Length - 1
            If Not Values(I) Is Nothing Then
                Values(I).Malen()
            End If
        Next
        For I = 0 To MultiValues.Length - 1
            If Not MultiValues(I) Is Nothing Then
                MultiValues(I).Malen()
            End If
        Next
        For I = 0 To CheckBoxen.Length - 1
            If Not CheckBoxen(I) Is Nothing Then
                CheckBoxen(I).Malen()
            End If
        Next
        For I = 0 To Labels.Length - 1
            If Not Labels(I) Is Nothing Then
                Labels(I).Malen()
            End If
        Next
        'Noch ein paar Sachen malen.
        Dim FocusObjekt As Integer = -1
        For I = 0 To Objekt2D.Objekte.Length - 1
            If Not Objekt2D.Objekte(I) Is Nothing Then
                If Objekt2D.Objekte(I).Focused Then
                    FocusObjekt = I
                Else
                    If TypeOf Objekt2D.Objekte(I) Is ObjektDropDownMenü Then
                        Objekt2D.Objekte(I).Malen()
                    ElseIf TypeOf Objekt2D.Objekte(I) Is ObjektTextbox Then
                        Objekt2D.Objekte(I).Malen()
                    End If
                End If
            End If
        Next
        If FocusObjekt >= 0 Then
            Objekt2D.Objekte(FocusObjekt).Malen()
        End If
        If IsNothing(Box) = False Then
            Box.Malen()
        End If
    End Sub

    ' Public MustOverride Sub ChangeWindowSize(ByVal PosChange As Point)
    Public MustOverride Sub ChangeWindowSize(ByVal PosChange As Point)

    ''' <summary>
    ''' Alle Objekte werden etwas verschoben.
    ''' </summary>
    ''' <param name="PosChange"></param>
    ''' <remarks></remarks>
    Protected Sub ChangeWindowSizeObjekte(ByVal PosChange As Point)
        For Each P In Panels
            P.ChangeWindowSize(PosChange)
        Next
        For Each Knopf In Knöpfe
            Knopf.ChangeWindowSize(PosChange)
        Next
        For Each NUD In NUDS
            NUD.ChangeWindowSize(PosChange)
        Next
        For Each SUD In SUDS
            SUD.ChangeWindowSize(PosChange)
        Next
        For Each Value In Values
            Value.ChangeWindowSize(PosChange)
        Next
        For Each Label In Labels
            Label.ChangeWindowSize(PosChange)
        Next
        For Each DropDownMenü In DropDownMenüs
            DropDownMenü.ChangeWindowSize(PosChange)
        Next
        For Each CheckBox In CheckBoxen
            CheckBox.ChangeWindowSize(PosChange)
        Next
        For Each Textbox In Textboxen
            Textbox.ChangeWindowSize(PosChange)
        Next
        For Each MultiValue In MultiValues
            MultiValue.ChangeWindowSize(PosChange)
        Next
        If Not Box Is Nothing Then
            Box.ChangeWindowSize(PosChange)
        End If
    End Sub
End Class
